/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Admin_EditItem.java
 *
 * Created on Mar 30, 2011, 3:35:59 PM
 */
package admin_gui;

import DTO.Category;
import admin.BusinessLogic.Validation;
import admin.Controller.ItemController;
import java.io.File;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

/**
 *
 * @author edaype
 */
public class Admin_EditItem extends javax.swing.JPanel {

    private ItemController itemController;
    private Vector edit_vect;
    private JFileChooser fc;
    private String[] sname;
    private Vector storeName;
    private String store;
    private String upc;
    private int ctid, originalCtid;
    private Validation validation;
    ArrayList<Category> list;
    DefaultMutableTreeNode root;

    /** Creates new form Admin_EditItem */
    public Admin_EditItem(ItemController aThis, Vector vector, Vector storeName) {
        
        this.itemController = aThis;
        initComponents();
        fc = new JFileChooser();
        edit_vect = (Vector) (vector.get(0));
        UPCField.setText((String) edit_vect.get(0));
        NameField.setText((String) edit_vect.get(1));
        PriceField.setText((String) edit_vect.get(4).toString());
        RetailField.setText((String) edit_vect.get(5).toString());
        DescriptionField.setText((String) edit_vect.get(6));
        DescriptionField.setLineWrap(true);
        DescriptionField.setWrapStyleWord(true);
        URLField.setText((String) edit_vect.get(7));
        MakeField.setText((String) edit_vect.get(2));
        ModelField.setText((String) edit_vect.get(3));
        String temp = edit_vect.get(8).toString();
        originalCtid = Integer.parseInt(temp);
        ctid = originalCtid;
        //       System.out.println("ctid"+ctid);
        this.storeName = storeName;
        sname = new String[storeName.size()];
        for (int i = 0; i < storeName.size(); i++) {
            sname[i] = ((Vector) storeName.elementAt(i)).get(0).toString();
        }
        StoreCombo.setModel(new javax.swing.DefaultComboBoxModel(sname));
        store = StoreCombo.getSelectedItem().toString();
        upc = "" + itemController.getItemQtyInStore(store, UPCField.getText());
        QtyField.setText(upc);
        list = itemController.getCategories();
        root = processTree(list, list.get(0));
        CategoryTree = new JTree(root);
        CategoryPane.setViewportView(CategoryTree);
        validation = new Validation();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LabelPanel1 = new javax.swing.JPanel();
        PriceLabel = new javax.swing.JLabel();
        RetailLabel = new javax.swing.JLabel();
        QtyLabel = new javax.swing.JLabel();
        StoreLabel = new javax.swing.JLabel();
        PriceField = new javax.swing.JTextField();
        QtyField = new javax.swing.JTextField();
        RetailField = new javax.swing.JTextField();
        StoreCombo = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        URLField = new javax.swing.JTextField();
        browser = new javax.swing.JButton();
        DescriptionPane = new javax.swing.JScrollPane();
        DescriptionField = new javax.swing.JTextArea();
        DescriptionLabel = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        NameLabel = new javax.swing.JLabel();
        MakeLabel = new javax.swing.JLabel();
        ModelLabel = new javax.swing.JLabel();
        ModelField = new javax.swing.JTextField();
        MakeField = new javax.swing.JTextField();
        NameField = new javax.swing.JTextField();
        CategoryPane = new javax.swing.JScrollPane();
        CategoryTree = new javax.swing.JTree();
        jLabel2 = new javax.swing.JLabel();
        UPCLabel = new javax.swing.JLabel();
        UPCField = new javax.swing.JTextField();
        ButtonLayout = new javax.swing.JPanel();
        SubmitButton = new javax.swing.JButton();
        ResetButton = new javax.swing.JButton();
        EditLabel = new javax.swing.JLabel();
        Back = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));

        LabelPanel1.setBackground(java.awt.Color.white);

        PriceLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        PriceLabel.setText("Cost Price");

        RetailLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        RetailLabel.setText("Retail Price");

        QtyLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        QtyLabel.setText("Quantity");

        StoreLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        StoreLabel.setText("Store");

        PriceField.setFont(new java.awt.Font("Tahoma", 0, 20));

        QtyField.setFont(new java.awt.Font("Tahoma", 0, 20));

        RetailField.setFont(new java.awt.Font("Tahoma", 0, 20));

        StoreCombo.setFont(new java.awt.Font("Tahoma", 0, 20));
        StoreCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StoreComboActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabel1.setText("URL");

        URLField.setFont(new java.awt.Font("Tahoma", 0, 20));

        browser.setText("...");
        browser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browserActionPerformed(evt);
            }
        });

        DescriptionField.setColumns(20);
        DescriptionField.setRows(5);
        DescriptionPane.setViewportView(DescriptionField);

        DescriptionLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        DescriptionLabel.setText("Description");

        javax.swing.GroupLayout LabelPanel1Layout = new javax.swing.GroupLayout(LabelPanel1);
        LabelPanel1.setLayout(LabelPanel1Layout);
        LabelPanel1Layout.setHorizontalGroup(
            LabelPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(LabelPanel1Layout.createSequentialGroup()
                .addGroup(LabelPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(LabelPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(LabelPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(DescriptionLabel)
                            .addComponent(StoreLabel)
                            .addComponent(RetailLabel)
                            .addComponent(PriceLabel))
                        .addGap(18, 18, 18)
                        .addGroup(LabelPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(DescriptionPane, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                            .addComponent(StoreCombo, javax.swing.GroupLayout.Alignment.TRAILING, 0, 242, Short.MAX_VALUE)
                            .addComponent(PriceField, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                            .addComponent(RetailField, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, LabelPanel1Layout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addComponent(QtyLabel)
                        .addGap(18, 18, 18)
                        .addComponent(QtyField, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, LabelPanel1Layout.createSequentialGroup()
                        .addGap(85, 85, 85)
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(URLField, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(browser, javax.swing.GroupLayout.PREFERRED_SIZE, 36, Short.MAX_VALUE)))
                .addContainerGap())
        );
        LabelPanel1Layout.setVerticalGroup(
            LabelPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(LabelPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(LabelPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(PriceLabel)
                    .addComponent(PriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(LabelPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(RetailLabel)
                    .addComponent(RetailField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addGroup(LabelPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(browser)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)
                    .addComponent(URLField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(LabelPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(QtyLabel)
                    .addComponent(QtyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(LabelPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(StoreCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(StoreLabel))
                .addGroup(LabelPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(LabelPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(DescriptionLabel))
                    .addGroup(LabelPanel1Layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(DescriptionPane, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jPanel1.setBackground(java.awt.Color.white);

        NameLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        NameLabel.setText("Name");

        MakeLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        MakeLabel.setText("Make");

        ModelLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        ModelLabel.setText("Model");

        ModelField.setFont(new java.awt.Font("Tahoma", 0, 20));

        MakeField.setFont(new java.awt.Font("Tahoma", 0, 20));

        NameField.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        NameField.setMaximumSize(new java.awt.Dimension(20, 2147483647));
        NameField.setMinimumSize(new java.awt.Dimension(70, 20));
        NameField.setPreferredSize(new java.awt.Dimension(2, 2));

        CategoryTree.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CategoryPane.setViewportView(CategoryTree);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabel2.setText("Category");

        UPCLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        UPCLabel.setText("UPC");

        UPCField.setEditable(false);
        UPCField.setFont(new java.awt.Font("Tahoma", 0, 20));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(CategoryPane, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(UPCLabel)
                                    .addComponent(NameLabel)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(MakeLabel)
                                    .addComponent(ModelLabel))))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(NameField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(MakeField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                            .addComponent(ModelField)
                            .addComponent(UPCField))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(UPCLabel)
                        .addGap(18, 18, 18))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(UPCField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(NameField, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)
                    .addComponent(NameLabel))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(MakeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(MakeLabel))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ModelField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ModelLabel))
                .addGap(18, 18, 18)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(CategoryPane, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE)
                .addContainerGap())
        );

        ButtonLayout.setBackground(new java.awt.Color(255, 255, 255));

        SubmitButton.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        SubmitButton.setText("Submit");
        SubmitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SubmitButtonActionPerformed(evt);
            }
        });

        ResetButton.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        ResetButton.setText("Reset");
        ResetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ResetButtonActionPerformed(evt);
            }
        });

        EditLabel.setFont(new java.awt.Font("Copperplate Gothic Bold", 2, 60));
        EditLabel.setText("Edit Item");

        Back.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        Back.setText("<Back");
        Back.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BackActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout ButtonLayoutLayout = new javax.swing.GroupLayout(ButtonLayout);
        ButtonLayout.setLayout(ButtonLayoutLayout);
        ButtonLayoutLayout.setHorizontalGroup(
            ButtonLayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ButtonLayoutLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(EditLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41)
                .addComponent(ResetButton, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(SubmitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22)
                .addComponent(Back, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(35, Short.MAX_VALUE))
        );
        ButtonLayoutLayout.setVerticalGroup(
            ButtonLayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ButtonLayoutLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ButtonLayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(Back, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, ButtonLayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(ButtonLayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ResetButton, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(SubmitButton, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE))
                        .addComponent(EditLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(LabelPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(ButtonLayout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(LabelPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(ButtonLayout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void ResetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ResetButtonActionPerformed
        // TODO add your handling code here:
        UPCField.setText((String) edit_vect.get(0));
        NameField.setText((String) edit_vect.get(1));
        PriceField.setText((String) edit_vect.get(4));
        RetailField.setText((String) edit_vect.get(5));
        DescriptionField.setText((String) edit_vect.get(6));
        URLField.setText((String) edit_vect.get(7));
        MakeField.setText((String) edit_vect.get(2));
        ModelField.setText((String) edit_vect.get(3));
        store = StoreCombo.getSelectedItem().toString();
        upc = "" + itemController.getItemQtyInStore(store, UPCField.getText());
        QtyField.setText(upc);
        ctid = originalCtid;
    }//GEN-LAST:event_ResetButtonActionPerformed

    private void SubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SubmitButtonActionPerformed
        String make = MakeField.getText();
        String model = ModelField.getText();
        String URL = URLField.getText();
        String name = NameField.getText();
        String price = PriceField.getText();
        String retail = RetailField.getText();
        String UPC = UPCField.getText();
        String description = DescriptionField.getText().replaceAll("'", "////'");
        String qty = QtyField.getText();
        DefaultMutableTreeNode selectedNode =
                (DefaultMutableTreeNode) CategoryTree.getLastSelectedPathComponent();
        if (qty.equals("") || make.equals("") || model.equals("") || URL.equals(
                "") || name.equals("") || price.equals("") || retail.equals("") || UPC.equals(
                "")) {
            JOptionPane.showMessageDialog(null, "Please input all information",
                    "Error", JOptionPane.ERROR_MESSAGE);
        } else if (!validation.ValidateInteger(qty)) {
            JOptionPane.showMessageDialog(null,
                    "The password has to be numberic",
                    "Error", JOptionPane.ERROR_MESSAGE);
        } else if (!validation.ValidateFloat(retail) || !validation.ValidateFloat(
                price)) {
            JOptionPane.showMessageDialog(null,
                    "The password has to be numberic",
                    "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            if (selectedNode != null) {
                Category selectedCategory =
                        (Category) selectedNode.getUserObject();
                if (selectedCategory.getCtid() != 0) {
                    DefaultMutableTreeNode parentNode =
                            (DefaultMutableTreeNode) selectedNode.getParent();
                    Category parentCategory =
                            (Category) parentNode.getUserObject();
                    ctid = selectedCategory.getCtid();
                }
            }
            itemController.updateItem(StoreCombo.getSelectedItem().toString(),
                    UPCField.getText(),
                    NameField.getText(),
                    MakeField.getText(),
                    ModelField.getText(),
                    PriceField.getText(),
                    RetailField.getText(),
                    DescriptionField.getText(),
                    URLField.getText(),
                    QtyField.getText(), ctid);
        }


    }//GEN-LAST:event_SubmitButtonActionPerformed

    private void browserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browserActionPerformed

        int returnVal = fc.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            URLField.setText(file.getName());
        } else {
           JOptionPane.showMessageDialog(null, "Can not set file",
                    "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_browserActionPerformed

    private void StoreComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StoreComboActionPerformed
        JComboBox cb = (JComboBox) evt.getSource();
        store = (String) cb.getSelectedItem();
        upc = "" + itemController.getItemQtyInStore(store, UPCField.getText());
        QtyField.setText(upc);
    }//GEN-LAST:event_StoreComboActionPerformed

    private void BackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BackActionPerformed
        itemController.goBackSerachItemPane();
    }//GEN-LAST:event_BackActionPerformed
    private DefaultMutableTreeNode processTree(ArrayList<Category> list,
            Category rootNode) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(rootNode);
        DefaultMutableTreeNode child;
        for (int i = 0; i < list.size(); i++) {
            Category nodeSpecifier = list.get(i);
            if (nodeSpecifier.getPctid() == rootNode.getCtid()) {
                child = processTree(list, nodeSpecifier);
                node.add(child);
            }
        }
        return node;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Back;
    private javax.swing.JPanel ButtonLayout;
    private javax.swing.JScrollPane CategoryPane;
    private javax.swing.JTree CategoryTree;
    private javax.swing.JTextArea DescriptionField;
    private javax.swing.JLabel DescriptionLabel;
    private javax.swing.JScrollPane DescriptionPane;
    private javax.swing.JLabel EditLabel;
    private javax.swing.JPanel LabelPanel1;
    private javax.swing.JTextField MakeField;
    private javax.swing.JLabel MakeLabel;
    private javax.swing.JTextField ModelField;
    private javax.swing.JLabel ModelLabel;
    private javax.swing.JTextField NameField;
    private javax.swing.JLabel NameLabel;
    private javax.swing.JTextField PriceField;
    private javax.swing.JLabel PriceLabel;
    private javax.swing.JTextField QtyField;
    private javax.swing.JLabel QtyLabel;
    private javax.swing.JButton ResetButton;
    private javax.swing.JTextField RetailField;
    private javax.swing.JLabel RetailLabel;
    private javax.swing.JComboBox StoreCombo;
    private javax.swing.JLabel StoreLabel;
    private javax.swing.JButton SubmitButton;
    private javax.swing.JTextField UPCField;
    private javax.swing.JLabel UPCLabel;
    private javax.swing.JTextField URLField;
    private javax.swing.JButton browser;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
